package com.geekerp.authorization_server.controller;


import com.geekerp.authorization_server.support.RedisOperator;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping
public class LoginController {

    @Autowired
    RedisOperator redisOperator;

    @GetMapping("/getSmsCode")
    public Map<String,Object> getSmsCaptcha(String phone,HttpSession session) {
        //随机成成四位验证码
        String captcha = "1234";
        //将验证码存入到redis中
        redisOperator.set("captcha:"+phone, captcha, 60);
        //返回验证码
        Map<String, Object> map2 = new HashMap<>();
        map2.put("captcha", captcha);
        Map<String,Object> map = new HashMap<>(16);
        map.put("mobile",phone);
        map.put("code",captcha);

        session.setAttribute("smsCode",map);
        return map;
    }




}
